﻿using Emgu.CV;
using Emgu.CV.Structure;
using Loli.Library.Util;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GameTools.Models
{
    public class DataCenter
    {


        public string _KeyLock = "KeyLock";
        public string _SkillLock = "SkillLock";
        public string _ScreenshotLock = "ScreenshotLock";

        private static DataCenter _DataCenter;

        public Image<Gray, byte> MonsterImage { get; set; }


        public Loli.Library.WinIo.Action _Action = null;

        public Config Config { get; set; }

        public Scripts Scripts { get; set; }
        public Maps Maps { get; set; }
        public Players Players { get; set; }


        public Map CurrentMap { get; set; }
        public Player CurrentPlayer { get; set; }
        public Map CurrentScript { get; set; }
        public Image<Gray, byte> DeathImage { get; set; }
        public Image<Gray, byte> VerificationImage { get; set; }
        public IntPtr Handle { get; set; }

        public string MathineCode { get; set; }
        public DateTime CurrentTime { get; set; }

        public static DataCenter Load()
        {
            if (_DataCenter == null)
            {
                _DataCenter = new DataCenter();
                _DataCenter.Config = Config.Load();

                // _DataCenter.Scripts = Scripts.Load();
                _DataCenter.Players = Players.Load();
                _DataCenter.Maps = Maps.Load();

                //获取默认的人物，地图，脚本
                _DataCenter.CurrentMap = _DataCenter.Maps.FirstOrDefault(t => t.Name == _DataCenter.Config.MapName);
                _DataCenter.CurrentPlayer = _DataCenter.Players.FirstOrDefault(t => t.Name == _DataCenter.Config.PlayerName);
                _DataCenter.CurrentScript = _DataCenter.Maps.FirstOrDefault(t => t.Name == _DataCenter.Config.ScriptName);

                //获取机器码
                MachineCode mathineCode = new MachineCode();

                string disk = mathineCode.GetHDid();

                string mac = mathineCode.GetMoAddress();

                CryptionData cd = new CryptionData("ancalimonssggwww");

                _DataCenter.MathineCode = cd.EncryptionStringData(mac + disk);
                _DataCenter._Action = new Loli.Library.WinIo.Action();

                //加载验证图片
                _DataCenter.DeathImage = new Image<Gray, byte>("Datas\\Death.arm");
                _DataCenter.VerificationImage = new Image<Gray, byte>("Datas\\Verification.arm");

                _DataCenter.CurrentTime = DateTimeUtil.GetBeijingTime();
            }

            return _DataCenter;
        }

    }
}
